package com.woniu.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.woniu.apartment.domain.Bed;
import com.woniu.apartment.service.IBedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房间床位Controller
 * 
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/apartment/tbbed")
@Api("房间床位管理")
public class BedController extends BaseController
{
    @Autowired
    private IBedService bedService;

    /**
     * 查询房间床位列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbbed:list')")
    @GetMapping("/list")
    @ApiOperation("房间床位分页查询")
    public TableDataInfo list(Bed bed)
    {
        startPage();
        List<Bed> list = bedService.selectBedList(bed);
        return getDataTable(list);
    }

    /**
     * 导出房间床位列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbbed:export')")
    @Log(title = "房间床位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("房间床位导出")
    public void export(HttpServletResponse response, Bed bed)
    {
        List<Bed> list = bedService.selectBedList(bed);
        ExcelUtil<Bed> util = new ExcelUtil<Bed>(Bed.class);
        util.exportExcel(response, list, "房间床位数据");
    }

    /**
     * 获取房间床位详细信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbbed:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("根据主键查询房间床位")
    @ApiImplicitParam(name = "ids", value = "用户ID", required = true, dataType = "Long")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bedService.selectBedById(id));
    }

    /**
     * 新增房间床位
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbbed:add')")
    @Log(title = "房间床位", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加房间床位")
    public AjaxResult add(@RequestBody Bed bed)
    {
        return toAjax(bedService.insertBed(bed));
    }

    /**
     * 修改房间床位
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbbed:edit')")
    @Log(title = "房间床位", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("更新房间床位")
    public AjaxResult edit(@RequestBody Bed bed)
    {
        return toAjax(bedService.updateBed(bed));
    }

    @RequestMapping("feign/edit")
    public Integer feignEdit(@RequestParam("bedId") Integer bedId){
        Bed bed = new Bed();
        bed.setId(Long.valueOf(bedId));
        bed.setStatus(2L);
       return bedService.updateBed(bed);
    }



    /**
     * 删除房间床位
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbbed:remove')")
    @Log(title = "房间床位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除房间床位")
    @ApiImplicitParam(name = "ids", value = "主键数组", required = true, dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bedService.deleteBedByIds(ids));
    }


}
